package com.jdojo.node;

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import static javafx.geometry.Orientation.HORIZONTAL;
import static javafx.geometry.Orientation.VERTICAL;

public class NodeSizeSentinelValues extends Application {
    public static void main(String[] args) {
        Application.launch(args);
    }

    @Override
    public void start(Stage stage) {
        Button okBtn = new Button("OK");
        Button cancelBtn = new Button("Cancel");
        // Override the intrinsic width of the cancel button
        cancelBtn.setPrefWidth(100);
        VBox root = new VBox();
        root.getChildren().addAll(okBtn, cancelBtn);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("Overriding Node Sizes");
        stage.show();
        System.out.println("okBtn.getPrefWidth(): " + okBtn.getPrefWidth());
        System.out.println("okBtn.getMinWidth(): " + okBtn.getMinWidth());
        System.out.println("okBtn.getMaxWidth(): " + okBtn.getMaxWidth());
        System.out.println("cancelBtn.getPrefWidth(): " + cancelBtn.getPrefWidth());
        System.out.println("cancelBtn.getMinWidth(): " + cancelBtn.getMinWidth());
        System.out.println("cancelBtn.getMaxWidth(): " + cancelBtn.getMaxWidth());
        System.out.println("--------------------------");
        double prefWidth = -1;
        double prefHeight = -1;
        Orientation contentBias = okBtn.getContentBias();
        if (contentBias == HORIZONTAL) {
            prefWidth = okBtn.prefWidth(-1);
            prefHeight = okBtn.prefHeight(prefWidth);
        } else if (contentBias == VERTICAL) {
            prefHeight = okBtn.prefHeight(-1);
            prefWidth = okBtn.prefWidth(prefHeight);
        } else {
            // contentBias is null
            prefWidth = okBtn.prefWidth(-1);
            prefHeight = okBtn.prefHeight(-1);
        }

        System.out.println(prefWidth + "," + prefHeight);

        double prefWidth1 = -1;
        double prefHeight1 = -1;
        Orientation contentBias1 = cancelBtn.getContentBias();
        if (contentBias1 == HORIZONTAL) {
            prefWidth1 = cancelBtn.prefWidth(-1);
            prefHeight1 = cancelBtn.prefHeight(prefWidth1);
        } else if (contentBias1 == VERTICAL) {
            prefHeight1 = cancelBtn.prefHeight(-1);
            prefWidth1 = cancelBtn.prefWidth(prefHeight1);
        } else {
            // contentBias is null
            prefWidth1 = cancelBtn.prefWidth(-1);
            prefHeight1 = cancelBtn.prefHeight(-1);
        }

        System.out.println(prefWidth1 + "," + prefHeight1);
    }
}